<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原生Ajax</title>
</head>

<body>
    <button id="btn_get">get</button>
    <!-- <button id="btn_post">post</button> -->
    <script>
        btn_get.addEventListener('click', () => {
            // alert('aa')
            var xhr = new XMLHttpRequest()
            xhr.open('get', 'http://127.0.0.1/api/recommend')
            xhr.send()
            xhr.onload = function () {
                let result = xhr.responseText
                console.log(JSON.parse(result));
            }
        })

        // btn_post.addEventListener('click', () => {
        //     // alert('aa')
        //     var xhr = new XMLHttpRequest()
        //     xhr.open('post', 'http://127.0.0.1/post')
        //     //发送
        //     let a = { name: 'song' }
        //     xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        //     xhr.send(JSON.stringify(a))
        //     xhr.onload = function () {
        //         let result = xhr.responseText
        //         console.log(result);
        //     }
        // })
    </script>
</body>

</html>